﻿using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FollowMe.AuthService.Messages;
using FollowMe.AuthService.Views;
using System.Web.Http;
using System.Net.Http;

/**
 * FollowMe Server
 * UWRF CS425 & CS343 Project Fall 2014
 * Adam Drews
 *   email adam.drews@my.uwrf.edu
 * Tyler Johnson
 *   email tyler.johnson@my.uwrf.edu
 * Nicholas Thorp
 *   email nicholas.thorp@my.uwrf.edu
 */
namespace FollowMe.AuthService
{
    //This is not used, but it could be expanded as a replacment to calls in the API
    //This does not require the HttpRequest: it requires the usermanager that is attached to the message.  Optionally switch those out.
    public static class AuthServices
    {
        public static RegisterResult register(AuthRegisterMemberRequest member, HttpRequestMessage request)
        {
            UserManager<AuthUser> owin = request.GetOwinContext().GetUserManager<AuthUserManager>();

            Guid guid = Guid.NewGuid();
            AuthUser user = new AuthUser(guid) { UserName = member.email, Email = member.email };
            IdentityResult task = owin.Create(user, member.password);
            
            RegisterResult ret = new RegisterResult
            {
                task = task,
                user = user,
                guid = guid
            };

            return ret;
        }

    }
}
